//添加图片 index为id名称
// var imgUrl = 'http://192.168.1.102:81';
/*function add_pic(index, max) {
    alert(iamges);
    images++;
    api.actionSheet({
        title: '请选择图片来源',
        cancelTitle: '取消',
        buttons: ['相册选取', '相机拍摄']
    }, function (ret, err) {
        var winWidth = api.winWidth;
        var listHeight = winWidth / 3 - 12;
        if (ret.buttonIndex == 1) {
            if ((/android/gi).test(navigator.appVersion)) {
                var album = api.require('UIMediaScanner');
                album.open({
                    column: 3,
                    max: max,
                    sort: {
                        key: 'time',
                        order: 'desc'
                    },
                    texts: {
                        stateText: '*',
                        cancelText: '取消',
                        finishText: '完成'
                    },
                    styles: {
                        bg: '#fff',
                        mark: {
                            icon: '',
                            position: 'bottom_right',
                            size: 20
                        },
                        nav: {
                            bg: '#FF8F00',
                            stateColor: '#ffffff',
                            stateSize: 18,
                            cancleBg: '#FF8F00',
                            cancelColor: '#ffffff',
                            cancelSize: 18,
                            finishBg: '#FF8F00',
                            finishColor: '#ffffff',
                            finishSize: 18
                        }
                    },
                    exchange: true
                }, function (ret) {
                    if (ret) {
                        var photoList = $api.byId(index);
                        var list = ret.list;
                        api.toast({
                            msg: '正在加载图片',
                            duration: 1000,
                            location: 'middle'
                        });
                        for (var i in list) {
                            var item = list[i];
                            var imgDom = $api.dom('.pics[src="' + item.thumbPath + '"]');
                            if (!imgDom) {
                                /!*$api.prepend(photoList, '<li class="li_pics" data-src="' + item.path + '" style="position:relative"><p class="state" id="' + item.path + '">正在上传</p><img class="pics" src="' + item.path + '"/><div style="display:block;height:20px;line-height:20px;text-align:center;width:20px;background:url(../image/del.png) no-repeat center center;background-size:60%;background-color:rgba(0,0,0,.6);color:#fff;position:absolute;bottom:0;right:0;z-index:8000" onclick="removePhoto(this)"></div></li>');*!/
                                $api.prepend(photoList, '<li><span class="deleIcon" tapmode onclick="delePic(this)"></span><img src="' + item.path + '"><input type="hidden" id="images' + i + '" value=""></li>');
                                api.parseTapmode();
                            }
                            uploadImage(item.path)
                        }
                    }
                });
            } else {
                api.getPicture({
                    sourceType: 'album',
                    encodingType: 'jpg',
                    mediaValue: 'pic',
                    destinationType: 'url',
                    allowEdit: false,
                    quality: 60,
                    targetWidth: 300,
                    saveToPhotoAlbum: true
                }, function (ret, err) {
                    var photoList = $api.byId(index);
                    if (ret.data) {
                        /!*$api.prepend(photoList, '<li class="li_pics" data-src="' + ret.data + '" style="position:relative"><p class="state" id="' + ret.data + '">正在上传</p><img class="pics" src="' + ret.data + '"/><div style="display:block;height:20px;line-height:20px;text-align:center;width:20px;background:url(../image/del.png) no-repeat center center;background-size:60%;background-color:rgba(0,0,0,.6);color:#fff;position:absolute;bottom:0px;right:0;z-index:8000" onclick="removePhoto(this)"></div></li>');*!/
                        $api.prepend(photoList, '<li><span class="deleIcon" tapmode onclick="delePic(this)"></span><img src="' + item.path + '"><input type="hidden" id="images0" value=""></li>');
                        api.parseTapmode();
                    }
                    uploadImage(ret.data)
                });
            }

        } else if (ret.buttonIndex == 2) {
            api.getPicture({
                sourceType: 'camera',
                encodingType: 'jpg',
                mediaValue: 'pic',
                destinationType: 'url',
                allowEdit: false,
                quality: 60,
                targetWidth: 300,
                saveToPhotoAlbum: true
            }, function (ret, err) {
                var photoList = $api.byId(index);
                if (ret.data) {
                    /!*$api.prepend(photoList, '<li class="li_pics" data-src="' + ret.data + '" style="position:relative"><p class="state" id="' + ret.data + '">正在上传</p><img class="pics" src="' + ret.data + '"/><div style="display:block;height:20px;line-height:20px;text-align:center;width:20px;background:url(../image/del.png) no-repeat center center;background-size:60%;background-color:rgba(0,0,0,.6);color:#fff;position:absolute;bottom:0px;right:0;z-index:8000" onclick="removePhoto(this)"></div></li>');*!/
                    $api.prepend(photoList, '<li><span class="deleIcon" tapmode onclick="delePic(this)"></span><img src="' + item.path + '"><input type="hidden" id="images0" value=""></li>');
                    api.parseTapmode();
                }
                uploadImage(ret.data)
            });
        }
    });
}

//移除图片
function removePhoto(span) {
    $api.remove($api.closest(span, '.li_pics'));
}

// 上传图片
function uploadImage(imgPath) {
    //alert(JSON.stringify(imgPath)); return false;
    var img = new Image();
    img.src = imgPath;
    //图片路径
    img.onload = function () {
        //生成比例
        var w = this.width, h = this.height, scale = w / h;
        w = 640 || w;
        h = w / scale;
        //生成canvas
        var canvas = document.createElement('canvas');
        var ctx = canvas.getContext('2d');
        $api.attr(canvas, 'width', '' + w + '');
        $api.attr(canvas, 'height', '' + h + '');
        ctx.drawImage(this, 0, 0, w, h);
        var base64 = canvas.toDataURL('image/jpeg');
        getStorageAll();
        //上传图片
        var upData = {
            userName: user_name,
            base64: base64,
            //是否生成浓缩图
            isthumbnail: 'true'
        }
        var url = 'Mall/imageUpload';
        ajaxRequest(url, 'post', upData, function (ret, err) {
            if (ret.status == 1) {

            } else {
                $api.remove($api.dom('.li_pics[data-src="' + imgPath + '"]'));
            }
        })
    }
}*/



